package main

import (
	"context"
	"github.com/gin-gonic/gin"
	_ "github.com/spf13/viper/remote"
	"go-admin/server/ioc"
	"net/http"
	"time"
)

func main() {
	ioc.InitOther()
	app := InitWebServer()
	server := app.web
	for _, c := range app.consumers {
		err := c.Start()
		if err != nil {
			panic(err)
		}
	}
	closeFunc := ioc.InitOTEL()
	startHeartbeat(server)
	server.Run(":8082")
	ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
	defer cancel()
	closeFunc(ctx)
}

// 检测心跳
func startHeartbeat(server *gin.Engine) {
	server.GET("/health", func(ctx *gin.Context) {
		ctx.JSON(http.StatusOK, gin.H{
			"msg":  "success_new",
			"code": http.StatusOK,
		})
	})
}
